// Copyright (c) Appeon. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. 
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

using System;
using System.Data.Common;
using System.Threading.Tasks;
using System.Threading;
using System.ComponentModel;

namespace SnapObjects.Data
{
    /// <summary>
    ///     Represents a connection to the database.
    /// </summary>
    public interface IAdoDbConnection : IAdoDbTransactionManager, IDisposable
    {
        /// <summary>
        ///     Gets the connection string used to open the database.
        /// </summary>
        string ConnectionString { get; }

        /// <summary>
        ///     Gets the GUID of this IAdoDbConnection object.
        /// </summary>
        Guid ConnectionId { get; }

        /// <summary>
        ///     Gets the internal DbConnection object.
        /// </summary>
        DbConnection DbConnection { get; }

        /// <summary>
        ///     Gets an IAdoDbTransaction object which represents the current database transaction.
        /// </summary>
        IAdoDbTransaction CurrentTransaction { get; }

        /// <summary>
        ///     Opens the database connection using the connection string.
        /// </summary>
        /// <returns>
        ///     Returns false if the current state of the connection is ConnectionState.Open; otherwise, 
        ///     returns true if a database connection is opened successfully.
        /// </returns>
        bool Open();

        Task<bool> OpenAsync();

        Task<bool> OpenAsync(CancellationToken cancellationToken);

        /// <summary>
        ///     Closes the connection to the database.
        /// </summary>
        /// <returns>
        ///     Returns false if the current state of the connection is ConnectionState.Closed or this connection 
        ///     was not opened in the current IAdoDbConnection object; otherwise, returns true if a database 
        ///     connection is closed successfully.
        /// </returns>
        bool Close();

        Task<bool> CloseAsync();
    }
}
